package com.ny.zmb.openapi.ysutil.from.merchant;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ny.zmb.openapi.entity.BaseObject;
import com.ny.zmb.openapi.enums.TransactionStatusEnum;
import com.ny.zmb.openapi.ysutil.annotation.Length;
import com.ny.zmb.openapi.ysutil.annotation.NotBlank;
import com.ny.zmb.openapi.ysutil.utils.RequestNoUntil;
import com.ny.zmb.openapi.ysutil.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.Date;

/**
 * 提现请求
 */
@Data
@AllArgsConstructor
@TableName("pm_merchant_withdraw_log")
public class MerchantWithdraw extends BaseObject {
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 用户id
     */
    private Long userId;
    /**
     * String	M	业务请求号
     */
    @NotBlank(message = "业务请求号" + "不能为空")
    @Length(max = 32, message = "业务请求号" + "长度超过" + "32" + "个字符")
    private String requestNo;
    /**
     * String	M	提现商户银盛商户号
     */
    private String merchantNo;
    /**
     * String	M	提现金额，单位：元 取值范围：0.01-9999999.99，保留2位小数
     */
    private BigDecimal amount;
    /**
     * String	M	提现资金账户类型01-一般消费类账户（bankAccountNo必填）02-待结算账户（商户结算方式为平台内时bankAccountNo必填，否则无法到账）
     */
    private String accountType;
    /**
     * String	M	银行附言，35个字节内 展示在银行明细中的附言（最终附言内容以银行实际账单为准）
     */
    private String remark;
    /**
     * String	M	提现银行卡号（仅已绑定的提现卡或结算卡）
     */
    private String bankAccountNo;
    /**
     * String	O	提现结果异步通知地址，为空则不通知
     */
    private String notifyUrl;

    private String returnData;

    public MerchantWithdraw() {
        setActive(1);
        setCreatedDate(new Date());
    }

    public void setUserId(Integer userId) {
        this.userId = Long.parseLong(userId.toString());
    }

    public void update(Object returnData, Integer userId) {
        this.returnData = returnData.toString();
        super.update(userId);
    }

    public void setRequestNo(String requestNo) {
        if (StringUtils.isEmpty(requestNo)) {
            this.requestNo = RequestNoUntil.generateNumericTaskNumber();
        } else {
            this.requestNo = requestNo;
        }
    }

    public void checkRequestNo() {
        if (StringUtils.isEmpty(requestNo)) {
            this.requestNo = RequestNoUntil.generateNumericTaskNumber();
        }
    }
}
